#include "scheduleinfo.h"
#include "remotedef.h"
#include <QVariant>
#include <QtDebug>

ScheduleInfo::ScheduleInfo()
    :BaseResp()
{
    schedules.clear();
}


void ScheduleInfo::unserialize(QString json)
{
    //json = "{\"code\":\"1000\",\"data\":[{\"type\":\"互动\",\"course_num\":\"123456\",\"name\":\"测试互动课1\",\"start_time\":\"2021-02-08 17:35:00\",\"end_time\":\"2021-03-08 21:35:00\",\"lecturer_device\":\"vt200\",\"participants\":[\"aa\",\"bb\",\"cc\",\"dd\",\"ee\"],\"lecturer\":\"哈哈哈\"},{\"type\":\"互动\",\"course_num\":\"7890102\",\"name\":\"测试互动课2\",\"start_time\":\"2021-02-09 07:35:00\",\"end_time\":\"2021-02-18 22:30:15\",\"lecturer_device\":\"vt200\",\"participants\":[\"张三\",\"李四\",\"王五\",\"赛罗奥特曼\",\"小猪佩奇\"],\"lecturer\":\"托马斯\"}]}";
    BaseResp::unserialize(json);
    if (m_json.isValid())
    {
        qDebug() << "shedule start" << endl;
        QList<OSDJson> list = m_json.getObjectArray();
        for(int i = 0; i < list.count(); i++)
        {
            qDebug() << "list:" << i<< endl;
            OSDJson obj = list.at(i);
            if (obj.isValid())
            {
                qDebug() << "obj:" << obj.str();
                schedule_t st;
                st.type = obj.value(KEY_SCHEDULE_TYPE).toString();
                st.name = obj.value(KEY_SCHEDULE_NAME).toString();
                st.start_time = obj.value(KEY_SCHEDULE_STARTTIME).toString();
                st.end_time = obj.value(KEY_SCHEDULE_ENDTIME).toString();
                st.lecturer = obj.value(KEY_SCHEDULE_LECTURER).toString();
                st.conference_number = obj.value(KEY_SCHEDULE_NUMBER).toString();
                st.lecturer_device = obj.value(KEY_SCHEDULE_DEVICE).toString();
                OSDJson parr = obj.object(KEY_SCHEDULE_PARTICI);
                QList<QVariant> ps;
                ps.clear();
                if (parr.isValid())
                {
                    ps = parr.getValueArray();
                }
                foreach(QVariant v, ps)
                {
                    st.participants.append(v.toString());
                }
                schedules.append(st);
            }
        }
        qDebug() << "shedule end";
    }
}

QList<ScheduleInfo::schedule_t> ScheduleInfo::getSchedules() const
{
    return schedules;
}

void ScheduleInfo::setSchedules(const QList<schedule_t> &value)
{
    schedules = value;
}

